package cn.js.sangu.unitStore.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.js.sangu.unitStore.dto.PartAttributeDTO;
import cn.js.sangu.unitStore.entity.ExcelData;
import cn.js.sangu.unitStore.entity.User;
import cn.js.sangu.unitStore.service.process.ExcelProcessService;
import cn.js.sangu.unitStore.utils.TokenUtils;

@Service
public class AutoCodeService {

    @Autowired
    private ExcelProcessService excelProcessService;

    public String autocode(PartAttributeDTO dto) {
        ExcelData data = new ExcelData();
        data.setTuhao(dto.getTuhao());
        data.setCailiao(dto.getCailiao());
        data.setGuige(dto.getGuige());
        data.setLeibie(dto.getLeibie());
        data.setName(dto.getName());

        // 获取当前登录用户的ID
        Integer creatorId = null;
        User currentUser = TokenUtils.getCurrentUser();
        if (currentUser != null) {
            creatorId = currentUser.getId();
        }

        return excelProcessService.autocode(data, creatorId, "页面单次");
    }

    public PartAttributeDTO parseAttributes(String code) {
        return excelProcessService.parseAttributes(code);
    }

    public void clearCount() {
        excelProcessService.clearCount();
    }

}
